package cn.edu.qfnu.oj.entity;

import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;

import javax.persistence.*;
import java.io.Serializable;
import java.time.LocalDateTime;

@Entity
@Table(name = "login_log")
public class LoginLog implements Serializable {

    private int id;  //登陆日志ID
    private String username; //登陆用户名
    private String ip; //登陆IP
    private LocalDateTime loginTime;  //登陆时间
    private String result;

    public LoginLog() {}

    public LoginLog(LocalDateTime loginTime, String...args) {
        this.username = args[0];
        this.ip = args[1];
        this.loginTime = loginTime;
        this.result = args[2];
    }

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Column(name = "username", nullable = false, length = 16)
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Column(name = "ip", length = 64)
    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    @Column(name = "login_time", nullable = false)
    public LocalDateTime getLoginTime() {
        return loginTime;
    }

    public void setLoginTime(LocalDateTime loginTime) {
        this.loginTime = loginTime;
    }

    @Column(length = 16)
    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;

        if (o == null || getClass() != o.getClass()) return false;

        LoginLog loginLog = (LoginLog) o;

        return new EqualsBuilder()
                .append(id, loginLog.id)
                .append(username, loginLog.username)
                .append(ip, loginLog.ip)
                .append(loginTime, loginLog.loginTime)
                .append(result, loginLog.result)
                .isEquals();
    }

    @Override
    public int hashCode() {
        return new HashCodeBuilder(17, 37)
                .append(id)
                .append(username)
                .append(ip)
                .append(loginTime)
                .append(result)
                .toHashCode();
    }
}
